/**
 * 
 */
package com.ja10.books;

import android.content.Context;
import android.database.DatabaseErrorHandler;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class SimpleDatabaseHelper extends SQLiteOpenHelper {

	static final private String name = "myfavorites.sqlite";
	static final private int version = 2;
	/**
	 * @param context
	 * @param name					:myfavorites.sqlite
	 * @param factory				: null
	 * @param version				: 1
	 */
	public SimpleDatabaseHelper(Context context) {
		super(context, name, null, version);
	}

	/* (非?Javadoc)
	 * @see android.database.sqlite.SQLiteOpenHelper#onOpen(android.database.sqlite.SQLiteDatabase)
	 */
	@Override
	public void onOpen(SQLiteDatabase db) {
		Log.d("DB", "onOpen");
		
		super.onOpen(db);
	}

	/* (非?Javadoc)
	 * @see android.database.sqlite.SQLiteOpenHelper#onCreate(android.database.sqlite.SQLiteDatabase)
	 */
	@Override
	public void onCreate(SQLiteDatabase db) {
		Log.d("DB", "onCreate");
		
		db.execSQL("CREATE TABLE myfavorites (" +
				"id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, " +
				"genre_name TEXT NOT NULL, " +
				"publisher_name TEXT NOT NULL, " +
				"title TEXT NOT NULL, " +
				"writer TEXT NOT NULL, " +
				"content TEXT, " +
				"record_date NUMERIC, " +
				"publication_date NUMERIC, " +
				"picture BLOB, " +
				"isbn TEXT NOT NULL)");
		
		db.execSQL("CREATE TABLE reserves (" +
				"id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, " +
				"genre_name TEXT NOT NULL, " +
				"publisher_name TEXT NOT NULL, " +
				"title TEXT NOT NULL, " +
				"writer TEXT NOT NULL, " +
				"content TEXT, " +
				"publication_date NUMERIC, " +
				"picture BLOB, " +
				"isbn TEXT NOT NULL, " +
				"reserve_date NUMERIC NOT NULL,  " +
				"reserve_plan_date NUMRIC NOT NULL )");
		
		db.execSQL("CREATE TABLE rentals (" +
				"id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, " +
				"title TEXT NOT NULL, " +
				"writer TEXT NOT NULL, " +
				"rental_date NUMERIC NOT NULL, " +
				"picture BLOB, " +
				"return_plan_date NUMRIC NOT NULL, " +
				"isbn TEXT NOT NULL)");
		
	}



	/* (非?Javadoc)
	 * @see android.database.sqlite.SQLiteOpenHelper#onUpgrade(android.database.sqlite.SQLiteDatabase, int, int)
	 */
	@Override
	public void onUpgrade(SQLiteDatabase db, int arg1, int arg2) {
		Log.d("DB", "onUpgrade");
		
		db.execSQL("DROP TABLE IF EXISTS myfavorites");
		onCreate(db);
	}

}
